/**********************************************
** @Des: This file ...
** @Author: xiaomeng79
** @Date:   17-11-16 下午5:29
***********************************************/
package controllers

import (
	"github.com/astaxie/beego"
	"strings"
)

const (
	MSG_OK  = 0
	MSG_ERR = -1
)

type BaseController struct {
	beego.Controller
}

//前期准备
func (this *BaseController) Prepare() {

}



// 是否POST提交
func (this *BaseController) isPost() bool {
	return this.Ctx.Input.IsPost()
}

// 是否AJAX提交
func (this *BaseController) IsAjax() bool {
	return this.Ctx.Input.IsAjax()
}

//获取用户IP地址
func (this *BaseController) getClientIp() string {
	s := strings.Split(this.Ctx.Request.RemoteAddr, ":")
	return s[0]
}

// 重定向
func (this *BaseController) redirect(url string) {
	this.Redirect(url, 302)
	this.StopRun()
}


//ajax返回
func (this *BaseController) ajaxMsg(msg interface{}, msgno int,data interface{}) {
	out := make(map[string]interface{})
	out["code"] = msgno
	out["message"] = msg
	out["data"] = data
	this.Data["json"] = out
	this.ServeJSON()
	this.StopRun()
}

//ajax返回 列表
func (this *BaseController) ajaxList(msg interface{}, msgno int, count int64, data interface{}) {
	out := make(map[string]interface{})
	out["code"] = msgno
	out["msg"] = msg
	out["count"] = count
	out["data"] = data
	this.Data["json"] = out
	this.ServeJSON()
	this.StopRun()
}